#!/usr/bin/env node

const log = console.log;

let buf1 = Buffer.alloc(256);
buf1[0] = 0;
log('buf1 length:',buf1.length);
log('buf1:',buf1);


//循环 初始化
for(let i=0; i<buf1.length; i++){
  buf1[i] = i;
}
log('\nbuf1:',buf1);

//切片操作
let buf2 = buf1.slice(247,256);
log('\nuf2:',buf2);

//填充数据
buf2.fill(0);
log('\nbuf2',buf2);
log('\nbuf2\'s JSON:',buf2.toJSON());
log('\nbuf2\'s JSON:',JSON.stringify(buf2));

//用数组初始化
let array = ['a',123,10,0xba];
let buf3 = Buffer.from(array);

//用字符串初始化
let buf4 = Buffer.from('hello world','utf8');

//复制
buf4.copy(buf3,0,0,buf3.length);

